package com.oamicnet.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.oamicnet.entity.User;

import java.util.Arrays;
import java.util.List;

public interface UserMapper extends BaseMapper<User> {

    // 插入一条数据
    default void insertUser() {
        User user = new User();
        user.setUsername("张三");
        user.setAge(20);
        user.setPhone("132000000");
        this.insert(user);
    }

    // 批量查询
    default List<User> batchSelect() {
        List<Long> ids = Arrays.asList(11L, 12L, 13L);
        return this.selectBatchIds(ids);
        
    }
    default List<User> searchByUserNameAndAge(String userName, Integer age) {
        // 查询名字为"张三"且年龄大于20的用户
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", userName)
        .gt("age", age);

        return this.selectList(queryWrapper);
    }

    /*public int insert();

    //保存
    public int save(User user);

    //更新
    int update(User user);

    //根据ID查询
    User getUser(int id);

    //列表查询
    List<User> getUsers(Map<String, Integer> map);

    //根据ID删除
    int deleteUser(int id);*/
}
